/* 引入Vue */
import Vue from 'vue'
/* 引入VueRouter */
import VueRouter from 'vue-router'
/* 引入常量路由规则表 */
import constantRoutes from "@/router/constantRoutes";
/* 使用VueRouter */
Vue.use(VueRouter)
/* 把VueRouter原型上的push和replace方法保存一份 */
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace
/* 重写VueRouter原型上的push的replace方法 */
VueRouter.prototype.push = function (location, resolve, reject) {
    if (resolve && reject) {
        // 如果传递了成功和失败的回调
        originPush.call(this, location, resolve, reject)
    } else {
        // 如果没有传递成功和失败的回调
        originPush.call(this, location, () => {
        }, () => {
        })
    }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
    if (resolve && reject) {
        // 如果传递了成功和失败的回调
        originReplace.call(this, location, resolve, reject)
    } else {
        // 如果没有传递成功和失败的回调
        originReplace.call(this, location, () => {
        }, () => {
        })
    }
}
/* 创建一个VueRouter的路由对象实例 */
const router = new VueRouter({
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
        return {x: 0, y: 0}
    }
})
/* 导出创建好的VueRouter实例 */
export default router
